package com.jowell.mall.product.mq;

import com.jowell.mall.product.config.MQConfig;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;
import java.io.IOException;
import java.lang.String;

/**
 * @Author: Mr.ZJW
 * @Date: 2022-07-08 16:29
 * @Description: MQ消费者
 */
@Component
public class ProductConsumer {

    @RabbitListener(queues = MQConfig.DIRECT_QUERY)
    public void product(String msg, Message message, Channel channel) throws IOException {
        try {
            System.out.println("receiver success  ProductConsumer->" + msg);
            System.out.println("唯一标识:"+message.getMessageProperties().getCorrelationId());
            //手动ack
            channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
